﻿<DataGrid x:Class="GrilleComptes"
          xml:lang="fr-FR"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          xmlns:Actuariat="clr-namespace:Actuariat"
          xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
          mc:Ignorable="d"
          Background="White"
          CanUserReorderColumns="False"
          CanUserSortColumns="False"
          CanUserDeleteRows="False"
          CanUserAddRows="False"
          CanSelectMultipleItems="False"
          CellStyle="{DynamicResource DataGridCellComptesStyle}"
          SelectionMode="Single"
          SelectionUnit="CellOrRowHeader"
          AutoGenerateColumns="True"
          ItemsSource="{Binding TableContenu}"
          GridLinesVisibility="None"
          IsReadOnly="True" Style="{DynamicResource DataGridStyle2}">
    
    <DataGrid.Resources>
        
        <Style x:Key="DataGridCellComptesStyle" TargetType="{x:Type DataGridCell}">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="Foreground" Value="Black"/>
                    <Setter Property="BorderBrush" Value="Transparent"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="ThumbStyleLeftGrilleCompte" TargetType="{x:Type Thumb}">
            <Setter Property="Cursor" Value="SizeWE"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Border Margin="0,1,0,1" BorderThickness="1,0,0,0" 
                            BorderBrush="{DynamicResource BrushCouleur1Base}" 
                            Background="Transparent" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ThumbStyleRightGrilleCompte" TargetType="{x:Type Thumb}">
            <Setter Property="Cursor" Value="SizeWE"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Border BorderThickness="0,0,1,0" 
                            BorderBrush="{DynamicResource BrushCouleur1Base}" 
                            Background="Transparent" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="Alignment" TargetType="{x:Type TextBlock}">
            <Setter Property="TextAlignment" Value="Right"></Setter>
            <Setter Property="Margin" Value="2,0,2,0"></Setter>
        </Style>
        <Style x:Key="DataGridStyle2" TargetType="{x:Type DataGrid}">
        	<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        	<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        	<Setter Property="BorderBrush" Value="#FF688CAF"/>
        	<Setter Property="BorderThickness" Value="1"/>
        	<Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
        	<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
        	<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        	<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="{x:Type DataGrid}">
        				<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
        					<ScrollViewer x:Name="DG_ScrollViewer" Focusable="false">
        						<ScrollViewer.Template>
        							<ControlTemplate TargetType="{x:Type ScrollViewer}">
        								<Grid>
        									<Grid.ColumnDefinitions>
        										<ColumnDefinition Width="Auto"/>
        										<ColumnDefinition Width="*"/>
        										<ColumnDefinition Width="Auto"/>
        									</Grid.ColumnDefinitions>
        									<Grid.RowDefinitions>
        										<RowDefinition Height="Auto"/>
        										<RowDefinition Height="*"/>
        										<RowDefinition Height="Auto"/>
        									</Grid.RowDefinitions>
        									<Button Command="{x:Static DataGrid.SelectAllCommand}" Focusable="false" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Background="White" Visibility="Hidden"/>
        									<DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
        									<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" Grid.ColumnSpan="2" Grid.Row="1"/>
        									<ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="2" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Grid.Row="1" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"/>
        									<Grid Grid.Column="1" Grid.Row="2">
        										<Grid.ColumnDefinitions>
        											<ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
        											<ColumnDefinition Width="*"/>
        										</Grid.ColumnDefinitions>
        										<ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
        									</Grid>
        								</Grid>
        							</ControlTemplate>
        						</ScrollViewer.Template>
        						<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
        					</ScrollViewer>
        				</Border>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        	<Style.Triggers>
        		<Trigger Property="IsGrouping" Value="true">
        			<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
        		</Trigger>
        	</Style.Triggers>
        </Style>
        
    </DataGrid.Resources>
    
    <DataGrid.RowHeaderStyle>
        <Style TargetType="{x:Type DataGridRowHeader}">
            <Setter Property="Content" Value="{Binding ComptesHeaders}"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                        <ContentPresenter Margin="0"
                                          HorizontalAlignment="Stretch" 
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                          VerticalAlignment="Stretch"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGrid.RowHeaderStyle>
    
    <DataGrid.RowHeaderTemplateSelector>
        <Actuariat:CompteRowHeaderTemplateSelector>
            <Actuariat:CompteRowHeaderTemplateSelector.TitreCompteTemplate>
                <DataTemplate>
                    <TextBlock Background="{StaticResource BrushCouleurComp9}" 
                               FontWeight="Bold" 
                               Margin="0" 
                               Text="{Binding Valeur}"></TextBlock>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.TitreCompteTemplate>
            <Actuariat:CompteRowHeaderTemplateSelector.Titre1Template>
                <DataTemplate>
                    <Border BorderBrush="Black" BorderThickness="0,0,1,0">
                        <TextBlock FontWeight="Bold" Margin="0" Text="{Binding}"></TextBlock>
                    </Border>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.Titre1Template>
            <Actuariat:CompteRowHeaderTemplateSelector.Titre11Template>
                <DataTemplate>
                    <Border BorderBrush="Black" BorderThickness="0,0,1,0">
                        <TextBlock Margin="0" Text="{Binding}"></TextBlock>
                    </Border>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.Titre11Template>
            <Actuariat:CompteRowHeaderTemplateSelector.Titre12Template>
                <DataTemplate>
                    <Border BorderBrush="Black" BorderThickness="0,0,1,0">
                        <TextBlock Margin="0" Text="{Binding}"></TextBlock>
                    </Border>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.Titre12Template>
            <Actuariat:CompteRowHeaderTemplateSelector.Titre13Template>
                <DataTemplate>
                    <Border BorderBrush="Black" BorderThickness="0,0,1,0">
                        <TextBlock Margin="0" Text="{Binding}"></TextBlock>
                    </Border>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.Titre13Template>
            <Actuariat:CompteRowHeaderTemplateSelector.Titre2Template>
                <DataTemplate>
                    <Border BorderBrush="Black" BorderThickness="0,0,1,0">
                        <TextBlock FontWeight="Normal" Margin="10,0,10,0" Text="{Binding}"></TextBlock>
                    </Border>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.Titre2Template>
            <Actuariat:CompteRowHeaderTemplateSelector.ResultatTemplate>
                <DataTemplate>
                    <Border BorderBrush="Black" BorderThickness="0,0,1,0">
                        <TextBlock FontWeight="Bold" 
                                   Background="{StaticResource BrushCouleurComp8}" 
                                   Text="{Binding}"></TextBlock>
                    </Border>
                </DataTemplate>
            </Actuariat:CompteRowHeaderTemplateSelector.ResultatTemplate>
        </Actuariat:CompteRowHeaderTemplateSelector>
    </DataGrid.RowHeaderTemplateSelector>
    
    <DataGrid.RowStyleSelector>
        <Actuariat:CompteRowStyleSelector>
            <Actuariat:CompteRowStyleSelector.TitreCompteStyle>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
                    <!--<Setter Property="Background" Value="White"/>-->
                    <Setter Property="BorderThickness" Value="0,0,0,1"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                    <Setter Property="SnapsToDevicePixels" Value="true"/>
                    <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
                    <Setter Property="ValidationErrorTemplate">
                        <Setter.Value>
                            <ControlTemplate>
                                <TextBlock Foreground="Red" Margin="2,0,0,0" Text="!" VerticalAlignment="Center"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type DataGridRow}">
                                <Border Background="White"
                                        BorderBrush="{TemplateBinding BorderBrush}" 
                                        BorderThickness="{TemplateBinding BorderThickness}">
                                    <Border x:Name="DGR_Border"
                                        Margin="0,20,0,5"
                                        Background="{StaticResource BrushCouleurComp9}"
                                        SnapsToDevicePixels="True">
                                        <SelectiveScrollingGrid>
                                            <SelectiveScrollingGrid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </SelectiveScrollingGrid.ColumnDefinitions>
                                            <SelectiveScrollingGrid.RowDefinitions>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="Auto"/>
                                            </SelectiveScrollingGrid.RowDefinitions>
                                            <DataGridCellsPresenter Grid.Column="1" 
                                                                ItemsPanel="{TemplateBinding ItemsPanel}"
                                                                Background="Red"
                                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                            <DataGridDetailsPresenter Grid.Column="1" 
                                                                  Grid.Row="1" 
                                                                  SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Visibility="{TemplateBinding DetailsVisibility}"/>
                                            <DataGridRowHeader Grid.RowSpan="2"
                                                           SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" 
                                                           Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                                        </SelectiveScrollingGrid>
                                    </Border>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Actuariat:CompteRowStyleSelector.TitreCompteStyle>
            <Actuariat:CompteRowStyleSelector.Titre1Style>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="BorderThickness" Value="0,0,1,0"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                </Style>
            </Actuariat:CompteRowStyleSelector.Titre1Style>
            <Actuariat:CompteRowStyleSelector.Titre11Style>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="BorderThickness" Value="0,0,1,0"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                    <Setter Property="FontWeight"  Value="Regular"/>
                </Style>
            </Actuariat:CompteRowStyleSelector.Titre11Style>
            <Actuariat:CompteRowStyleSelector.Titre12Style>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="BorderThickness" Value="0,0,1,0"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                    <Setter Property="FontWeight"  Value="Regular"/>
                </Style>
            </Actuariat:CompteRowStyleSelector.Titre12Style>
            <Actuariat:CompteRowStyleSelector.Titre13Style>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="BorderThickness" Value="0,0,1,1"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                    <Setter Property="FontWeight"  Value="Regular"/>
                </Style>
            </Actuariat:CompteRowStyleSelector.Titre13Style>
            <Actuariat:CompteRowStyleSelector.Titre2Style>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="BorderThickness" Value="0,0,1,0"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                    <Setter Property="FontWeight"  Value="Regular"/>
                </Style>
            </Actuariat:CompteRowStyleSelector.Titre2Style>
            <Actuariat:CompteRowStyleSelector.ResultatStyle>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="BorderThickness" Value="0,0,1,1"/>
                    <Setter Property="BorderBrush" Value="Black"/>
                    <Setter Property="Background" Value="{StaticResource BrushCouleurComp8}" />
                </Style>
            </Actuariat:CompteRowStyleSelector.ResultatStyle>
        </Actuariat:CompteRowStyleSelector>
    </DataGrid.RowStyleSelector>
    
    <DataGrid.ColumnHeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Background" Value="{DynamicResource BrushCouleur1Base}" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Height" Value="24"/>
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                        <Grid OverridesDefaultStyle="False">
                            <Microsoft_Windows_Themes:DataGridHeaderBorder 
							BorderBrush="{DynamicResource BrushCouleur1Base}" 
							BorderThickness="0" 
							Background="{DynamicResource BrushCouleur1Base}"
							IsClickable="{TemplateBinding CanUserSort}" 
							IsPressed="{TemplateBinding IsPressed}" 
							IsHovered="{TemplateBinding IsMouseOver}"
							Padding="{TemplateBinding Padding}" 
							SortDirection="{TemplateBinding SortDirection}" 
							SeparatorBrush="Black" 
							SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
                                <ContentPresenter Margin="2,0,2,0"
                                                  HorizontalAlignment="Right" 
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  Content="{TemplateBinding ContentControl.Content}"/>
                            </Microsoft_Windows_Themes:DataGridHeaderBorder>
                            <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{DynamicResource ThumbStyleLeftGrilleCompte}" Background="Transparent" Width="8"/>
                            <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{DynamicResource ThumbStyleRightGrilleCompte}" Background="Transparent" Width="8"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGrid.ColumnHeaderStyle>

</DataGrid>